package com.tibbytang.opengllearn.train09

import android.opengl.GLES20
import android.opengl.GLES30
import android.opengl.GLSurfaceView
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.tibbytang.opengllearn.R
import com.tibbytang.opengllearn.shape.Line
import com.tibbytang.opengllearn.util.Logger
import kotlinx.android.synthetic.main.activity_line.*
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10

class TriangleStripActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_line)
        line_surface_view.setEGLContextClientVersion(2)
        line_surface_view.setEGLConfigChooser(8, 8, 8, 8, 16, 4);
        val render = LineRender()
        line_surface_view.setRenderer(render)
        line_surface_view.renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY
    }

    inner class LineRender : GLSurfaceView.Renderer {
        private lateinit var line: Line
        override fun onDrawFrame(p0: GL10?) {
            Logger.info("onDrawFrame")
            GLES20.glClear(GLES30.GL_COLOR_BUFFER_BIT)
            line.draw()
        }

        override fun onSurfaceChanged(p0: GL10?, p1: Int, p2: Int) {
            Logger.info("onSurfaceChanged")
            GLES20.glViewport(0, 0, p1, p2)
        }

        override fun onSurfaceCreated(p0: GL10?, p1: EGLConfig?) {
            line = Line()
            Logger.info("onSurfaceCreated")
            GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f)
        }

    }
}
